# -*- coding:utf-8 -*-
"""
该脚本为单独的创建各阶段本地工程目录
"""

import os
try:
    import maya.cmds as cmds
except Exception as test_ERR:
    print('test')


def create_mm_dir(drive_path,project,eps,asset_shot,pipeline):

    mm_asset_path = os.path.join(drive_path, project, 'mm_asset')
    if not os.path.exists(mm_asset_path):
        os.makedirs(mm_asset_path)

    pf_path = os.path.join(drive_path, project, eps, 'pf')
    if not os.path.exists(pf_path):
        os.makedirs(pf_path)

    mm_path = os.path.join(drive_path, project, eps, asset_shot,pipeline)
    if not os.path.exists(mm_path):
        os.makedirs(mm_path)
    mm_dirs = ['3de', 'abc','download', 'fbx', 'nuke', 'stmap', 'systheyes', 'ud', 'movies','images','sourceimages','scenes','shot']
    for i in mm_dirs:
        dirs_path = os.path.join(mm_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    return mm_path


def create_mod_dir(drive_path,project,eps,asset_shot,pipeline):
    sourceimages_path = os.path.join(drive_path, project, 'sourceimages')
    if not os.path.exists(sourceimages_path):
        os.makedirs(sourceimages_path)
    mod_path = os.path.join(drive_path, project,eps,asset_shot, pipeline)
    if not os.path.exists(mod_path):
        os.makedirs(mod_path)
    mod_dirs = ['ae','abc' ,'download','fbx', 'mari', 'nuke', 'other', 'ps', 'sp',
                'speedtree', 'zbrush', 'movies','images','sourceimages','scenes']
    for i in mod_dirs:
        dirs_path = os.path.join(mod_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    return mod_path


def create_rig_dir(drive_path,project,eps,asset_shot,pipeline):

    rig_asset_path = os.path.join(drive_path, project, eps,'rig_asset') # 整个项目资产路径
    if not os.path.exists(rig_asset_path):
        os.makedirs(rig_asset_path)
    rig_path = os.path.join(drive_path, project, eps,asset_shot, pipeline)
    if not os.path.exists(rig_path):
        os.makedirs(rig_path)
    rig_dirs = ['abc', 'cfx','download', 'fbx',  'mod', 'mudbox', 'other', 'obj',
                'wrap3', 'zbrush', 'movies','images','sourceimages','scenes']
    for i in rig_dirs:
        dirs_path = os.path.join(rig_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    return rig_path


def create_ani_dir(drive_path,project,eps,asset_shot,pipeline):
    # ani_path = ''
    # ani_dirs = []
    # if module == 'asset':
    #     ani_path = os.path.join(drive_path, project,eps, asset_shot, pipeline)
    #     if not os.path.exists(ani_path):
    #         os.makedirs(ani_path)
    #     ani_dirs = ['abc', 'fbx', 'movies','images','sourceimages','scenes']
    #
    # else:
    ani_path = os.path.join(drive_path, project, eps, asset_shot, pipeline)
    if not os.path.exists(ani_path):
        os.makedirs(ani_path)
    ani_dirs = ['abc', 'ae','download', 'cam', 'fbx', 'nuke', 'pr','movies','images','sourceimages','scenes']

    for i in ani_dirs:
        dirs_path = os.path.join(ani_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)

    return ani_path


def create_env_dir(drive_path,project,eps,asset_shot,pipeline):
    sourceimages_path = os.path.join(drive_path, project, 'sourceimages')
    if not os.path.exists(sourceimages_path):
        os.makedirs(sourceimages_path)
    env_path = os.path.join(drive_path, project,eps, asset_shot, pipeline)
    if not os.path.exists(env_path):
        os.makedirs(env_path)
    env_dirs = ['abc', 'max','download', 'fbx',  'nuke', 'UE', 'clarrise','movies','images','sourceimages','scenes']
    for i in env_dirs:
        dirs_path = os.path.join(env_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    return env_path


def create_lgt_dir(drive_path,project,eps,asset_shot,pipeline):

    lgt_asset_path = os.path.join(drive_path, project, 'lgt_asset')
    if not os.path.exists(lgt_asset_path):
        os.makedirs(lgt_asset_path)
    lgt_path = os.path.join(drive_path, project, eps, asset_shot, pipeline)
    if not os.path.exists(lgt_path):
        os.makedirs(lgt_path)
    lgt_dirs = ['abc','fbx','download','houdini', 'nuke', 'shot','movies','images','sourceimages','scenes']
    for i in lgt_dirs:
        dirs_path = os.path.join(lgt_path, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    return lgt_path

def create_cfx_dir(drive_path,project,eps,asset_shot,pipeline):
    project_math = os.path.join(drive_path, project, eps, asset_shot, pipeline)
    if not os.path.exists(project_math):
        os.makedirs(project_math)
    dir_list = ['hip', 'geo', 'cam', 'abc', 'tex', 'fbx', 'img', 'nk', 'hda', 'DCC', 'deadline']
    for i in dir_list:
        dirs_path = os.path.join(project_math, i)
        if not os.path.exists(dirs_path):
            os.makedirs(dirs_path)
    maya_path = os.path.join(drive_path, project, eps, asset_shot, pipeline,'maya')
    if not os.path.exists(maya_path):
        os.makedirs(maya_path)
    maya_list = ['assets', 'autosave', 'clips', 'data', 'images', 'movies', 'renderData', 'sceneAssembly', 'scenes',
                 'scripts', 'sound', 'sourceimages', 'Time Editor', 'cache','haircache']
    for o in maya_list:
        folder_path = os.path.join(maya_path, o)
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)
    return maya_path

def createProjectDir(drive_path,project,eps,asset_shot,pipeline):
    dir_path = ''
    if pipeline == 'mm':
        dir_path = create_mm_dir(drive_path,project,eps,asset_shot,pipeline)
    elif pipeline == 'mod':
        dir_path = create_mod_dir(drive_path,project,eps,asset_shot,pipeline)
    elif pipeline == 'rig':
        dir_path = create_rig_dir(drive_path, project, eps, asset_shot, pipeline)
    elif pipeline == 'ani':
        dir_path = create_ani_dir(drive_path, project, eps, asset_shot, pipeline)
    elif pipeline == 'env':
        dir_path = create_env_dir(drive_path, project, eps, asset_shot, pipeline)
    elif pipeline == 'env':
        dir_path = create_lgt_dir(drive_path, project, eps, asset_shot, pipeline)
    elif pipeline == 'lgt':
        dir_path = create_lgt_dir(drive_path, project, eps, asset_shot, pipeline)
    elif pipeline == 'cfx':
        dir_path = create_cfx_dir(drive_path, project, eps, asset_shot, pipeline)

    return dir_path

def setWorkspace(project_path):
    """
    设置工程项目路径
    :param project_path:
    :return:
    """
    cmds.workspace( project_path, openWorkspace=True )
    cmds.workspace( saveWorkspace=True )







if __name__ == '__main__':
    """
    test
    """
    drive_path = 'E:'
    project = 'CXRX'
    eps = 'pianhua'
    asset_shot = ''
    createProjectDir(drive_path,project,eps,asset_shot,'mm')





